package com.dzh.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @Author 戴志豪
 * @date 2022/10/10 10:48
 */
public class Primefactor {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("num：");
        int i = scanner.nextInt();


        List<Integer> list = getFactor(i);

        System.out.print(i + "=");
        for (Integer integer : list) {
            if (integer.equals(list.get(list.size() - 1))){
                System.out.print(integer);
                break;
            }
            System.out.print(integer + "*");
        }

    }

    /**
     * 获取质因数列表
     * @param num   入参
     * @return      质因数列表
     */
    public static List<Integer> getFactor(int num){
        List<Integer> list = new ArrayList<>();

        for (int i1 = 2; i1 <= num; i1++) {
            if (num % i1 == 0) {
                list.add(i1);
                num /= i1;
                i1 = 1;
            }
        }
        return list;
    }
}
